package cn.yx.framework.form;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017-02-10.
 */
public class Query {
    Logger logger = LoggerFactory.getLogger(Query.class);
    public static final int PAGE_SIZE = 20;
    private int numPerPage = 20;
    private int pageNum = 1;
    private Map<String, Object> conditions = new HashMap();
    private String orderField;
    private String orderDirection;
    private String keywords;
    private Date start;
    private Date end;

    public Query(int pageSize, int pageIndex) {
        this.numPerPage = pageSize;
        this.pageNum = pageIndex;
    }

    public int getNumPerPage() {
        return this.numPerPage;
    }

    public void setNumPerPage(int numPerPage) {
        this.numPerPage = numPerPage;
    }

    public int getPageNum() {
        return this.pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public Map<String, Object> getConditions() {
        return this.conditions;
    }

    public void setConditions(Map<String, Object> conditions) {
        this.conditions = conditions;
    }

    public String getOrderField() {
        return this.orderField;
    }

    public void setOrderField(String orderField) {
        this.orderField = orderField;
    }

    public String getOrderDirection() {
        return this.orderDirection;
    }

    public void setOrderDirection(String orderDirection) {
        this.orderDirection = orderDirection;
    }

    public String getKeywords() {
        return this.keywords;
    }

    public void setKeywords(String keywords) {
        if(null != keywords && keywords.trim().length() != 0) {
            String tempStr = keywords.replaceAll("\'|=|;|\\*|\"|!|~|$|%|^|&|\\(|\\)", "").replaceAll("<", "").replaceAll(">", "").replaceAll("\'", "").replaceAll("\\(", "").replaceAll("gt;", "").replaceAll("lt;", "").replaceAll("or|like|and|between|top|script|delete|drop|select|where|exec|from|alert", "").replaceAll("\\s", "");
            this.logger.debug("\n\n\n===========Keywords==============\n" + keywords + "\n过滤后:" + tempStr + "\n\n\n===========Keywords==============");
            this.keywords = tempStr;
        } else {
            this.keywords = null;
        }
    }

    public Date getStart() {
        return this.start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return this.end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }
}
